package com.spider.spiderorderbasedata.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.spider.spiderorderbasedata.mapper.DataOrganizationMapper;
import com.spider.spiderorderbasedata.model.entity.DataOrganization;
import com.spider.spiderorderbasedata.service.DataOrganizationService;
import org.springframework.stereotype.Service;

/**
 * @author xiong.bo
 * @version 1.0
 * @date 2024/5/10 8:20 下午
 */
@Service
public class DataOrganizationServiceImpl extends ServiceImpl<DataOrganizationMapper, DataOrganization>
        implements DataOrganizationService {

    @Override
    public IPage<DataOrganization> selectPage(int page, int pageSize) {
        Page<DataOrganization> pageObject = new Page(page, pageSize);
        LambdaQueryWrapper<DataOrganization> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.orderByDesc(DataOrganization::getCreateTime);
        return this.baseMapper.selectPage(pageObject, queryWrapper);
    }

    @Override
    public DataOrganization findById(Long id) {
        return this.getById(id);
    }

    @Override
    public DataOrganization saveOrganization(DataOrganization dataOrganization) {
        this.save(dataOrganization);
        return dataOrganization;
    }

    @Override
    public DataOrganization editOrganization(DataOrganization dataOrganization) {
        this.updateById(dataOrganization);
        return dataOrganization;
    }

    @Override
    public Boolean deleteOrganization(Long id) {
        return this.removeById(id);
    }
}
